<div id="pointsLogPage" class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">积分日志</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>积分日志</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <form class="layui-form toolbar" name="queryForm">
            <div class="layui-inline">
                用户昵称：
                <input name="nickName" type="text" class="layui-input search-input enterSubmit" placeholder="请输入">
            </div>
            &nbsp;&nbsp;
            <div class="layui-inline">
                类型：
                <select id="pointsRuleType" name="pointType">
                    <option value="">-请选择规则类型-</option>
                </select>&emsp;
            </div>
            &nbsp;&nbsp;
            <div class="layui-inline">
                创建时间
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" name="startDate" class="layui-input" id="startDate" placeholder="开始时间">
                </div>
                <div class="layui-input-inline" style="width: 150px;">
                    <input type="text" name="endDate" class="layui-input" id="endDate" placeholder="结束时间">
                </div>
            </div>
            &nbsp;&nbsp;
            <button id="points-btn-search" class="layui-btn icon-btn" lay-submit lay-filter="query"><i
                    class="layui-icon">&#xe615;</i>搜索
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <!--<button id="points-btn-add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>-->
        </form>

        <!-- 数据表格 -->
        <table class="layui-table" id="pointsLog-table" lay-filter="pointsLog-table"></table>
    </div>
</div>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin', 'laydate'], function () {
        let form = layui.form;
        let table = layui.table;
        let config = layui.config;
        let layer = layui.layer;
        let util = layui.util;
        let admin = layui.admin;
        let laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#startDate'
            , type: 'datetime'
        });
        laydate.render({
            elem: '#endDate'
            , type: 'datetime'
        });

        let url = config.base_server + 'api-points/pointsLog/getPointsLog';
        let params = {
            access_token: config.getToken().access_token
        };
        let cols = [[
            {type: 'numbers'},
            {field: 'id', sort: true, title: 'ID', width: 100},
            {field: 'nickName', sort: true, title: '用户昵称', align: 'center'},
            {field: 'pointRule', sort: true, title: '规则描述', align: 'center'},
            {field: 'name', sort: true, title: '规则类型', align: 'center'},
            {field: 'points', sort: true, title: '积分值', align: 'center'},
            {
                field: 'createTime', sort: true, templet: function (d) {
                    return util.toDateString(d.createTime);
                }, title: '创建时间'
            }
        ]];

        // 渲染表格
        table.render({
            elem: '#pointsLog-table',
            url: url,
            where: params,
            page: true,
            cols: cols
        });

        // 填充下拉列表 - 积分规则类型
        admin.req('api-points/pointsRuleType/get', {}, (data) => {
            $.each(data.data, function (index, item) {
                let option = new Option(item.name, item.code);
                $("#pointsLogPage select[name='pointType']").append(option);
            });
            form.render();
        }, 'GET');

        // 条件检索
        form.on('submit(query)', (data) => {
            table.reload('pointsLog-table', {where: data.field});
            return false;
        });

        // 回车查询
        $('.enterSubmit').keyup((e) => {
            switch (e.keyCode) {
                case 13:
                    $('#points-btn-search').click();
                    break;
            }
        });

    });
</script>